package edu.pku.sei.transformation.mtparser;

import lpg.runtime.*;

public class KWMTLexer extends KWMTLexerprs
{
    private char[] inputChars;
    private final int keywordKind[] = new int[30 + 1];

    public int[] getKeywordKinds() { return keywordKind; }

    public int lexer(int curtok, int lasttok)
    {
        int current_kind = getKind(inputChars[curtok]),
            act;

        for (act = tAction(START_STATE, current_kind);
             act > NUM_RULES && act < ACCEPT_ACTION;
             act = tAction(act, current_kind))
        {
            curtok++;
            current_kind = (curtok > lasttok
                                   ? Char_EOF
                                   : getKind(inputChars[curtok]));
        }

        if (act > ERROR_ACTION)
        {
            curtok++;
            act -= ERROR_ACTION;
        }

        return keywordKind[act == ERROR_ACTION  || curtok <= lasttok ? 0 : act];
    }

    public void setInputChars(char[] inputChars) { this.inputChars = inputChars; }


    final static int tokenKind[] = new int[128];
    static
    {
        tokenKind['$'] = KWMTLexersym.Char_DollarSign;
        tokenKind['%'] = KWMTLexersym.Char_Percent;
        tokenKind['_'] = KWMTLexersym.Char__;

        tokenKind['a'] = KWMTLexersym.Char_a;
        tokenKind['b'] = KWMTLexersym.Char_b;
        tokenKind['c'] = KWMTLexersym.Char_c;
        tokenKind['d'] = KWMTLexersym.Char_d;
        tokenKind['e'] = KWMTLexersym.Char_e;
        tokenKind['f'] = KWMTLexersym.Char_f;
        tokenKind['g'] = KWMTLexersym.Char_g;
        tokenKind['h'] = KWMTLexersym.Char_h;
        tokenKind['i'] = KWMTLexersym.Char_i;
        tokenKind['j'] = KWMTLexersym.Char_j;
        tokenKind['k'] = KWMTLexersym.Char_k;
        tokenKind['l'] = KWMTLexersym.Char_l;
        tokenKind['m'] = KWMTLexersym.Char_m;
        tokenKind['n'] = KWMTLexersym.Char_n;
        tokenKind['o'] = KWMTLexersym.Char_o;
        tokenKind['p'] = KWMTLexersym.Char_p;
        tokenKind['q'] = KWMTLexersym.Char_q;
        tokenKind['r'] = KWMTLexersym.Char_r;
        tokenKind['s'] = KWMTLexersym.Char_s;
        tokenKind['t'] = KWMTLexersym.Char_t;
        tokenKind['u'] = KWMTLexersym.Char_u;
        tokenKind['v'] = KWMTLexersym.Char_v;
        tokenKind['w'] = KWMTLexersym.Char_w;
        tokenKind['x'] = KWMTLexersym.Char_x;
        tokenKind['y'] = KWMTLexersym.Char_y;
        tokenKind['z'] = KWMTLexersym.Char_z;

        tokenKind['A'] = KWMTLexersym.Char_A;
        tokenKind['B'] = KWMTLexersym.Char_B;
        tokenKind['C'] = KWMTLexersym.Char_C;
        tokenKind['D'] = KWMTLexersym.Char_D;
        tokenKind['E'] = KWMTLexersym.Char_E;
        tokenKind['F'] = KWMTLexersym.Char_F;
        tokenKind['G'] = KWMTLexersym.Char_G;
        tokenKind['H'] = KWMTLexersym.Char_H;
        tokenKind['I'] = KWMTLexersym.Char_I;
        tokenKind['J'] = KWMTLexersym.Char_J;
        tokenKind['K'] = KWMTLexersym.Char_K;
        tokenKind['L'] = KWMTLexersym.Char_L;
        tokenKind['M'] = KWMTLexersym.Char_M;
        tokenKind['N'] = KWMTLexersym.Char_N;
        tokenKind['O'] = KWMTLexersym.Char_O;
        tokenKind['P'] = KWMTLexersym.Char_P;
        tokenKind['Q'] = KWMTLexersym.Char_Q;
        tokenKind['R'] = KWMTLexersym.Char_R;
        tokenKind['S'] = KWMTLexersym.Char_S;
        tokenKind['T'] = KWMTLexersym.Char_T;
        tokenKind['U'] = KWMTLexersym.Char_U;
        tokenKind['V'] = KWMTLexersym.Char_V;
        tokenKind['W'] = KWMTLexersym.Char_W;
        tokenKind['X'] = KWMTLexersym.Char_X;
        tokenKind['Y'] = KWMTLexersym.Char_Y;
        tokenKind['Z'] = KWMTLexersym.Char_Z;
    };

    final int getKind(char c)
    {
        return (((c & 0xFFFFFF80) == 0) /* 0 <= c < 128? */ ? tokenKind[c] : 0);
    }


    public KWMTLexer(char[] inputChars, int identifierKind)
    {
        this.inputChars = inputChars;
        keywordKind[0] = identifierKind;

        //
        // Rule 1:  KeyWord ::= i f
        //
        
		keywordKind[1] = (MTParsersym.TK_if);
	  
	
        //
        // Rule 2:  KeyWord ::= t h e n
        //
        
		keywordKind[2] = (MTParsersym.TK_then);
	  
	
        //
        // Rule 3:  KeyWord ::= e l s e
        //
        
		keywordKind[3] = (MTParsersym.TK_else);
	  
	
        //
        // Rule 4:  KeyWord ::= e n d i f
        //
        
		keywordKind[4] = (MTParsersym.TK_endif);
	  
	
        //
        // Rule 5:  KeyWord ::= f o r e a c h
        //
        
		keywordKind[5] = (MTParsersym.TK_foreach);
	  
	
        //
        // Rule 6:  KeyWord ::= f o r a l l
        //
        
		keywordKind[6] = (MTParsersym.TK_forall);
	  
	
        //
        // Rule 7:  KeyWord ::= e x i s t o n e
        //
        
		keywordKind[7] = (MTParsersym.TK_existone);
	  
	
        //
        // Rule 8:  KeyWord ::= n e w
        //
        
		keywordKind[8] = (MTParsersym.TK_new);
	  
	
        //
        // Rule 9:  KeyWord ::= d e l e t e
        //
        
		keywordKind[9] = (MTParsersym.TK_delete);
	  
	
        //
        // Rule 10:  KeyWord ::= a n d
        //
        
		keywordKind[10] = (MTParsersym.TK_and);
	  
	
        //
        // Rule 11:  KeyWord ::= o r
        //
        
		keywordKind[11] = (MTParsersym.TK_or);
	  
	
        //
        // Rule 12:  KeyWord ::= n o t
        //
        
		keywordKind[12] = (MTParsersym.TK_not);
	  
	
        //
        // Rule 13:  KeyWord ::= t r a n s f o r m a t i o n
        //
        
		keywordKind[13] = (MTParsersym.TK_transformation);
	  
	
        //
        // Rule 14:  KeyWord ::= r u l e
        //
        
		keywordKind[14] = (MTParsersym.TK_rule);
	  
	
        //
        // Rule 15:  KeyWord ::= n u l l
        //
        
		keywordKind[15] = (MTParsersym.TK_null);
	  
	
        //
        // Rule 16:  KeyWord ::= i n v a l i d
        //
        
		keywordKind[16] = (MTParsersym.TK_invalid);
	  
	
        //
        // Rule 17:  KeyWord ::= c h e c k
        //
        
		keywordKind[17] = (MTParsersym.TK_check);
	  
	
        //
        // Rule 18:  KeyWord ::= e n f o r c e
        //
        
		keywordKind[18] = (MTParsersym.TK_enforce);
	  
	
        //
        // Rule 19:  KeyWord ::= m a t c h
        //
        
		keywordKind[19] = (MTParsersym.TK_match);
	  
	
        //
        // Rule 20:  KeyWord ::= f u l l
        //
        
		keywordKind[20] = (MTParsersym.TK_full);
	  
	
        //
        // Rule 21:  KeyWord ::= p a r t i a l
        //
        
		keywordKind[21] = (MTParsersym.TK_partial);
	  
	
        //
        // Rule 22:  KeyWord ::= d e f
        //
        
		keywordKind[22] = (MTParsersym.TK_def);
	  
	
        //
        // Rule 23:  KeyWord ::= b a s e d
        //
        
		keywordKind[23] = (MTParsersym.TK_based);
	  
	
        //
        // Rule 24:  KeyWord ::= t r u e
        //
        
		keywordKind[24] = (MTParsersym.TK_true);
	  
	
        //
        // Rule 25:  KeyWord ::= f a l s e
        //
        
		keywordKind[25] = (MTParsersym.TK_false);
	  
	
        //
        // Rule 26:  KeyWord ::= e n v
        //
        
		keywordKind[26] = (MTParsersym.TK_env);
	  
	
        //
        // Rule 27:  KeyWord ::= t r a c e
        //
        
		keywordKind[27] = (MTParsersym.TK_trace);
	  
	
        //
        // Rule 28:  KeyWord ::= e v a l u a t e
        //
        
		keywordKind[28] = (MTParsersym.TK_evaluate);
	  
	
        //
        // Rule 29:  KeyWord ::= e x c l u s i v e V a r s
        //
        
		keywordKind[29] = (MTParsersym.TK_exclusiveVars);
	  
	
        //
        // Rule 30:  KeyWord ::= u n i o n
        //
        
		keywordKind[30] = (MTParsersym.TK_union);
	  
	
        for (int i = 0; i < keywordKind.length; i++)
        {
            if (keywordKind[i] == 0)
                keywordKind[i] = identifierKind;
        }
    }
}

